package com.shopping_back.controller;

import com.shopping_back.common.Result;
import com.shopping_back.service.IDashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 仪表盘数据接口
 */
@RestController
@RequestMapping("/api/dashboard")
@RequiredArgsConstructor
public class DashboardController {

    private final IDashboardService dashboardService;

    /**
     * 获取订单状态分布
     * GET /api/dashboard/order-status-distribution
     * @return [{ status: int, count: long }, ...]
     */
    @GetMapping("/order-status-distribution")
    public Result getOrderStatusDistribution() {
        List<Map<String, Object>> list = dashboardService.getOrderStatusDistribution();
        return Result.success(list);
    }

    /**
     * 获取商品销量排行榜（Top N）
     * GET /api/dashboard/top-selling-skus?topN=10
     * @param topN 前 N 名，默认 10
     * @return [{ skuName: String, sales: long }, ...]
     */
    @GetMapping("/top-selling-skus")
    public Result getTopSellingSkus(@RequestParam(defaultValue = "10") int topN) {
        List<Map<String, Object>> list = dashboardService.getTopSellingSkus(topN);
        return Result.success(list);
    }

    /**
     * 获取促销活动参与度对比
     * GET /api/dashboard/promotion-participation
     * @return [{ activityName: String, quantity: long }, ...]
     */
    @GetMapping("/promotion-participation")
    public Result getPromotionParticipation() {
        List<Map<String, Object>> list = dashboardService.getPromotionParticipation();
        return Result.success(list);
    }

    /**
     * 获取评价星级分布
     * GET /api/dashboard/evaluation-rating-distribution
     * @return [{ score: int, count: long }, ...]
     */
    @GetMapping("/evaluation-rating-distribution")
    public Result getEvaluationRatingDistribution() {
        List<Map<String, Object>> list = dashboardService.getEvaluationRatingDistribution();
        return Result.success(list);
    }
}
